class_name xuanwo
extends Area2D
@export var speed:float =200
@export var rot_delta:float = 1
@export var end_pos:Vector2=Vector2.ZERO
var begin_pos := Vector2.ZERO
var to_end:bool = true
var dir:Vector2
@export var push :bool = true
var fif=1.0
func _ready() -> void:
	if push :
		fif = 1.0
	else:
		fif = -1.0
	begin_pos = self.global_position
	dir  = end_pos.normalized()



func _process(delta: float) -> void:
	rotation_degrees+=delta*rot_delta
	if to_end:
		global_position+=dir*speed*delta
		if abs((global_position-begin_pos).length()-end_pos.length())<15:
			to_end=false
	else:
		global_position-=dir*speed*delta
		if (global_position-begin_pos).length()<15:
			to_end = true
	var bodys = get_overlapping_bodies()
	for i in bodys:
		if i is Player:
			i.xuanwo_dir =(40+8000/(50+(i.global_position-self.global_position).length()))*fif*(i.global_position-self.global_position).normalized()


func _on_body_exited(body: Node2D) -> void:
	if body is Player:
		body.xuanwo_dir = Vector2.ZERO
